<?php
    use User\Model\LiveModel;
?>
<style>
    .table>tbody>tr>td{vertical-align: middle}
    .table>tbody>tr>td>a{margin-top:5px}
</style>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">直播房间</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a style="margin-left:7px" href="/User/Live/edit" class="btn btn-success">新增</a>
                    <a href="javascript:;" id="deleteAll" class="btn btn-danger">删除</a>
                    <form class="input-group" action="/User/Live/index" style="width: 300px;float:right">
                        <input type="text" class="form-control" name="title" placeholder="输入标题搜索" value="{$title}">
                        <span class="input-group-btn">
							<button class="btn btn-default" type="submit">
								<i class="fa fa-search"></i>
							</button>
						</span>
                    </form>
                </div>
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="selectAll"></th>
                                    <th>房间号</th>
                                    <th>房间名称</th>
                                    <th>主播</th>
                                    <th>直播地址</th>
                                    <th>创建时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <volist name="list" id="item">
                                    <tr>
                                        <td><input type="checkbox" name="ids" value="{$item.id}"></td>
                                        <td>{$item.id}</td>
                                        <td>{$item.title}</td>
                                        <td>{$liveUser[$item['userid']]['account']}</td>
                                        <td>{$item.link}</td>
                                        <td>{$liveUser[$item['userid']]['createdate']}</td>
                                        <td>
                                            <if condition="$item.status eq LiveModel::ROOM_ACTIVE">
                                                <span class="label label-success">发布</span>
                                            <elseif condition="$item.status eq LiveModel::ROOM_APPLY"/>
                                                <span class="label label-warning">停用</span>
                                            <else/>
                                                <span class="label label-warning">已删除</span>
                                            </if>
                                        </td>
                                        <td>
                                            <a type="button" href="/User/Live/edit?id={$item['id']}" class="btn btn-info">编辑</a>
                                            <a type="button" href="/User/Live/topic?room_id={$item['id']}" class="btn btn-primary">话题</a>
                                            <a type="button" href="javascript:;" onclick="return statusLive({$item['id']}, 'active');" class="btn btn-success">发布</a>
                                            <a type="button" href="javascript:;" onclick="return statusLive({$item['id']}, 'apply');" class="btn btn-warning">停用</a>
                                            <a type="button" href="javascript:;" onclick="return statusLive({$item['id']}, 'delete');" class="btn btn-danger">删除</a>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                        <div class="pages">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $("#selectAll").click(function(){
        if($(this).prop('checked') == true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    })

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids != ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/Live/deletes',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请勾选直播房间！');
        }
    });

    function statusLive(id, status){
        if(status == "active"){
            if(!confirm('确认发布吗？')) return false;
        }else if(status == "apply"){
            if(!confirm('确认停用吗？')) return false;
        }else{
            if(!confirm('确认删除吗？')) return false;
        }
        $.ajax({
            data: {id: id, status: status},
            dataType: 'json',
            url: '/User/Live/statusLive',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }
</script>